﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetBranchActivityList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            BranchActivityOutParam result = new BranchActivityOutParam();
            BranchActivityInParam param = new BranchActivityInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as BranchActivityInParam;
                if (param.page_no <= 0 || param.page_count <= 0)
                {
                    result.code = "0";
                    result.desc = "请求参数不正确";

                    isFlag = false;
                }

                if(isFlag)
                {
                    DataTable dt = InterfaceHelper.QueryNews("D658070EC3BF425BA8417745FDCBFCB0", param.page_no, param.page_count);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        BranchActivity itemTemp;
                        string url = CommonUtils.AppAddressEx + "html/InformationDetail.aspx?InfoType={0}&InfoID={1}";
                        //result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[0].Rows[0][0]), param.page_count);
                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(InterfaceHelper.GetCount("D658070EC3BF425BA8417745FDCBFCB0")), param.page_count);
                        foreach (DataRow dr in dt.Rows)
                        {
                            itemTemp = new BranchActivity();
                            //itemTemp.activity_actor = InterfaceHelper.QueryActivityMembers(dr["msg_id"].ToString());
                            itemTemp.activity_addr = dr["activity_addr"].ToString();
                            itemTemp.activity_content = dr["activity_content"].ToString();
                            itemTemp.activity_note_url = string.Format(url, dr["infoType"], dr["msg_id"]);
                            itemTemp.activity_time = dr["activity_time"].ToString();
                            itemTemp.branch_id = dr["branch_id"].ToString();
                            itemTemp.branch_name = CommonUtils.ChangeBranchName(dr["branch_name"].ToString());
                            itemTemp.msg_id = dr["msg_id"].ToString();
                            itemTemp.isfirst = dr["isfirst"].ToString().ToLower() == "true" ? "1" : "0"; 
                            itemTemp.publish_time = Convert.ToDateTime(dr["publish_time"]).ToString("yyyy-MM-dd HH:mm");
                            itemTemp.push_time = Convert.ToDateTime(dr["push_time"]).ToString("yyyy-MM-dd HH:mm");
                            itemTemp.title = dr["title"].ToString();
                            itemTemp.category = dr["category"].ToString();

                            result.data.list.Add(itemTemp);
                        }
                    } 
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetBranchActivityList", SerializeHelper.JsonSerializer<BranchActivityInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<BranchActivityInParam, BranchActivityOutParam>();
            else
                SafeProcessRequest<BranchActivityInParam, BranchActivityOutParam>();
        }
    }

    #region 请求参数
    public class BranchActivityInParam
    { 
        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class BranchActivityOutParam
    {
        public BranchActivityOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new BranchActivityList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 支部活动列表
        /// </summary>
        public BranchActivityList data
        { get; set; }
    }

    public class BranchActivityList
    {
        public BranchActivityList()
        {
            total_pages = 0;
            list = new List<BranchActivity>();
        }

        public List<BranchActivity> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }
     
    /// <summary>
    /// 支部活动列表
    /// </summary>
    public class BranchActivity
    {
        /// <summary>
        /// 资讯ID
        /// </summary>
        public string msg_id
        { get; set; }

        /// <summary>
        /// 资讯标题
        /// </summary>
        public string title
        { get; set; }

        /// <summary>
        /// 发布时间
        /// </summary>
        public string publish_time
        { get; set; }

        /// <summary>
        /// 推送时间 yyyy-MM-dd hh:ss
        /// </summary>
        public string push_time
        { get; set; }

        /// <summary>
        /// 所属支部ID
        /// </summary>
        public string branch_id
        { get; set; }

        /// <summary>
        /// 所属支部名称
        /// </summary>
        public string branch_name
        { get; set; }

        /// <summary>
        /// 活动时间
        /// </summary>
        public string activity_time
        { get; set; }

        /// <summary>
        /// 活动地址
        /// </summary>
        public string activity_addr
        { get; set; }

        /// <summary>
        /// 活动内容
        /// </summary>
        public string activity_content
        { get; set; }

        /// <summary>
        /// 活动参与者
        /// </summary>
        public string activity_actor
        { get; set; }

        /// <summary>
        /// 活动记录详情HTML页面地址
        /// </summary>
        public string activity_note_url
        { get; set; }

        /// <summary>
        ///  是否置顶 1　是　0 否
        /// </summary>
        public string isfirst
        { get; set; }

        /// <summary>
        /// 类别:支部活动/一支部一品牌
        /// </summary>
        public string category
        { get; set; } 
    }
    #endregion 
}